package com.hst.web.base.proxy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.hst.core.Page;
import com.hst.core.ServiceContext;
import com.hst.core.dao.IORDao;
import com.hst.core.dao.ISQLDao;
import com.hst.core.meta.proxies.DefaultDataProxy;
import com.hst.core.meta.proxies.OREntityUtils;
import com.hst.web.auth.po.User;
import com.hst.web.base.service.UserRoleService;
import com.hst.web.common.utils.ConstantUtil;
import com.hst.web.sys.entity.TRole;

public class VehicleCardApproveProxy extends DefaultDataProxy{
	
	@Autowired
	IORDao dao;
	
	@Autowired
	ISQLDao sql;
	
	@Autowired
	UserRoleService us;
	
	@Autowired
	OREntityUtils orUtil;
	
	@SuppressWarnings({ "unchecked", "static-access" })
	@Override
	public Page<?> list(Map<String, ?> query, int pageIdx) {
		User u =(User) ServiceContext.getInstance().getUser();
		TRole role = us.userRole(u.getId());
		Map<String,Object> map = new HashMap<String, Object>();
		map = (Map<String, Object>) query;
		List<TRole> userRoleList = us.getUserRole(u.getId());		//增加多角色时的审批条件
		if (userRoleList.size() == 0) {
			map.put("next1", null);
		} else {
			for (int i = 0; i < userRoleList.size(); i++) {
				map.put("next" + (i+1), userRoleList.get(i).getId());
			}
		}
		
		if("9".equals(role.getRoleLevel())) {
			
		}else if("1".equals(role.getRoleLevel())){
			map.put("companyCode", u.getCompanyCode());
			map = (Map<String, Object>) us.addContractorEmpParam(map);
		}else if("2".equals(role.getRoleLevel())) {
			if (u.getPrivileges().contains(ConstantUtil.COMPANY_MANAGER_PRIVLIGE)) {// 企业管理员
				map.put("companyCode", u.getCompanyCode());
			}else {
				map = (Map<String, Object>) us.addCompanyEmpParam(map);
			}
		}
		map.put("id", u.getId());
		map.put("userid", u.getUserid());
		Page<?> p = sql.list("vehicle.listApproveAndHistory",map, pageIdx, Page.getPageSize());
		return p;
	}
}
